# encoding: utf-8
# Datetime  : 2020/5/29 6:10 PM
# User      : zzz
# File      : data_access.py.py
import os

import pandas as pd

# machine number
total_machine = 2


def get_url_list():
    # get path of current directory
    curr_path = os.path.dirname(os.path.abspath(__file__))
    fname = os.path.join(curr_path, 'source/data.xlsx')
    df = pd.read_excel(fname, sheet_name='Sheet2', usecols='A')
    pd.set_option('max_colwidth', 200)
    return df.values.tolist()


def get_range_url(page=1):
    url_list = get_url_list()

    total = len(url_list)
    page_size = total // total_machine
    remainder = total % total_machine
    from_idx = (page - 1) * page_size
    end_idx = from_idx + remainder + page_size if page == total_machine else from_idx + page_size
    print(f"url size: {end_idx - from_idx}")
    return url_list[from_idx:end_idx]


if __name__ == '__main__':
    # list = get_url_list()
    # for url in list:
    #     print(url)

    get_range_url(6)
